package com.miaosha.redis.set;

import redis.clients.jedis.Jedis;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author lsq
 * @create 2021-10-16 18:04
 * @description
 * @menu
 **/
public class UVDemo {

    private Jedis jedis = new Jedis("182.42.113.98", 6379);

    public void addUserAccess(long userId) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String today = dateFormat.format(new Date());
        jedis.sadd("user_access::" + today, String.valueOf(userId));
    }

    public long getUV() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String today = dateFormat.format(new Date());
        return jedis.scard("user_access::" + today);
    }

    public static void main(String[] args) {
        UVDemo uvDemo = new UVDemo();
        for (int i = 0; i < 100; i++) {
            for (int i1 = 0; i1 < 10; i1++) {
                uvDemo.addUserAccess(i+1);
            }
        }

        System.out.println(uvDemo.getUV());
    }

}
